//从cookie中根据key取value
function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i].trim();
        if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
    }
    return "";
}

function hrefByGet(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = location.search.substr(1).match(reg);
    if (r != null) {
        return decodeURI(r[2]);
    }
    return "";
}

//错误提醒
function noMsg(title, offset) {
    layer.msg(title, {
        offset: offset,
        icon: 5,
        shift: 6
    });
}

//成功提醒
function yesMsg(title, offset) {
    layer.msg(title, {
        offset: offset,
        icon: 6
    });
}

layui.use('form', function () {
    var form = layui.form;
    //正则表达式
    form.verify({
        username: [/^[\S]{6,12}$/, '账号必须6到12位，且不能出现空格'],
        password: [/^[\S]{6,12}$/, '密码必须6到12位，且不能出现空格'],
        name: [/^[\u4e00-\u9fa5]{2,5}$/, '姓名为2-5个汉字'],
        age: [/^(?:[1-9][0-9]?|1[01][0-9]|120)$/, '年龄在1-120岁之间'],
        title: [/^[\S]{0,50}$/, '标题不能超过50个字符，且不能出现空格'],
        email: [/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, '请输入正确的邮箱'],
        phone: [/^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/, '请输入正确的手机号码'],
    });
});